//
//  GYStatusModel.swift
//  Weibo
//
//  Created by vane on 16/8/13.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class GYStatusModel: NSObject {
    
    // 创建时间
    var created_at: String?
    // 微博ID
    var id: Int64 = 0
    // 微博信息内容
    var text: String?
    // 微博来源
    var source: String?
    // 用户模型
    var user: GYUserModel?
    // 配图
    var pic_urls:[GYPictureInfo]?
    // 转发微博
    var retweeted_status:GYStatusModel?
    // int	转发数
    var reposts_count: Int = 0
    // int	评论数
    var comments_count: Int = 0
    //int	表态数
    var attitudes_count: Int = 0
    
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
        
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    // 重写setValueForKey
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            // 判断value 是否为nil 且是否可以转成一个字典
            guard let v = value as? [String: AnyObject] else{
                return
            }
            // 手动给user赋值
            user = GYUserModel(dict: v)
            
        }else if key == "retweeted_status"{
            
            guard let v = value as? [String: AnyObject] else{
                return
            }
            
            retweeted_status = GYStatusModel(dict: v)
            
        
        }else if key == "pic_urls"{
            
            guard let v = value as? [[String: AnyObject]] else{
                return
            }
            
            var tempArr:[GYPictureInfo] = [GYPictureInfo]()
            
            for dict in v {
                
                let pic = GYPictureInfo(dict: dict)
                
                tempArr.append(pic)
                
            }
            
            pic_urls = tempArr
            
            
        }else{
            super.setValue(value, forKey: key)
        }
    }

}
